<?php

class tsw_wind implements ThermdSingleWidget
{
  public function drawWidget($io,$x,$y)
  {
    $wr = ThermdStats::ts_readCurrent(ThermdStats::$windspeed_log_id,0);
    $wg = ThermdStats::ts_readCurrent(ThermdStats::$windgust_log_id,0);
    $black = imagecolorallocate($io,0,0,0);
    $val = array($wr,$wg);
  
		if($val[0]!==FALSE)
		{
		  $wr = $val[0];
		  $wg = $val[1];
		  
      $blue = imagecolorallocate($io,0,0,163);
		  $ablue = imagecolorallocate($io,0,38,255);
		  
		  imagestring($io,5,$x+132,$y+9,'Wind',$ablue);
    	// add the wind information and arrow if non zero
  		imagestring($io,5,$x+52,$y,'N',$blue);
  		imagestring($io,5,$x+103,$y+50,'E',$blue);
  		imagestring($io,5,$x+51,$y+102,'S',$blue);
  		imagestring($io,5,$x,$y+50,'W',$blue);

			if($wr>0)
			{
    		// lowest x = 413, lowest y = 16
				imagestring($io,5,$x+102,$y+24,ThermdStats::ts_windDirection(ThermdStats::ts_readCurrent(ThermdStats::$winddir_log_id,0)+ThermdStats::$winddir_offset).' @ '.$wr.ThermdStats::$windunits,$black);
				
				$bf = ThermdStats::ts_getBeaufort($wr);
				imagestring($io,2,$x+117,$y+63,'Beaufort: '.$bf[0],$ablue);
				imagestring($io,2,$x+115,$y+74,$bf[1],$ablue);
				$winddir = imagecreatefrompng(ThermdStats::$thermosrc."wind/".trim(ThermdStats::ts_windDirection(ThermdStats::ts_readCurrent(ThermdStats::$winddir_log_id,0)+ThermdStats::$winddir_offset)).".png");
	
				imagecopy($io,$winddir,$x+10,$y+14,0,0,91,90);	
				
			} else {
				imagestring($io,5,$x+132,$y+24,"Calm",$black); 
				$winddir = imagecreatefrompng(ThermdStats::$thermosrc."wind/CALM.png");
	
				imagecopy($io,$winddir,$x+10,$y+14,0,0,91,90);	
			}
			
			if($wg>0)
			{
				imagestring($io,2,$x+117,$y+39,'Gust: '.$wg.ThermdStats::$windunits,$black);
			}
		}
  }
}

?>